package org.jeecg.modules.crm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.crm.entity.CrmProject;
import org.jeecg.modules.crm.mapper.CrmProjectMapper;
import org.jeecg.modules.crm.service.ICrmProjectService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 项目信息
 * @Author: jeecg-boot
 * @Date:   2023-06-03
 * @Version: V1.0
 */
@Service
public class CrmProjectServiceImpl extends ServiceImpl<CrmProjectMapper, CrmProject> implements ICrmProjectService {

    private static final Logger log = LoggerFactory.getLogger(CrmProjectServiceImpl.class);

    @Override
    public List<CrmProject> getProjectsByCustomerId(String customerId) {
        return baseMapper.selectByCustomerId(customerId);
    }

    @Override
    public IPage<CrmProject> selectProjectPage(Page<CrmProject> page, CrmProject project) {
        return baseMapper.selectProjectPage(page, project);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByCustomerId(String customerId) {
        HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
        String username = JwtUtil.getUserNameByToken(request);
        return baseMapper.deleteLogicByCustomerId(customerId, username) >= 0;
    }

    @Override
    public IPage<CrmProject> getProjectPageList(Page<CrmProject> page, CrmProject project) {
        log.debug("执行getProjectPageList查询，查询条件: {}", project);
        return baseMapper.getProjectPageList(page, project);
    }
} 